package e.odbo.data.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ArrayUtils {
    public static <T> T[] concatAll(T[] first, T[]... rest) {
        int totalLength = first.length;
        for (T[] array : rest) {
            totalLength += array.length;
        }
        T[] result = Arrays.copyOf(first, totalLength);
        int offset = first.length;
        for (T[] array : rest) {
            System.arraycopy(array, 0, result, offset, array.length);
            offset += array.length;
        }
        return result;
    }

    public static int compareUseInteger(String[] src,String[] des){
        for(int i=0;i<src.length;i++)
            if (compareUseInteger(src[i], des[i]) != 0)
                return compareUseInteger(src[i], des[i]);
        return 0;
    }

    private static int compareUseInteger(String src,String des){
       return  Integer.valueOf(src).compareTo(Integer.valueOf(des));
    }

    public static <T> List<T> filter(T[] first,Comparable<T> filter){
        List<T> ret=new ArrayList<>();
        for(T obj:Arrays.asList(first))
            if(filter.compareTo(obj)==0)
                ret.add(obj);
         return  ret;
    }

}
